//
//  ZYStatusRetweetView.swift
//  WBBeta1
//
//  Created by wustzhy on 16/8/13.
//  Copyright © 2016年 Yestin. All rights reserved.
//

import UIKit
import SnapKit

class ZYStatusRetweetView: UIView {
    
    var retweetViewBottomConstraint: Constraint?
    
    var statusViewModel:ZYStatusViewModel?{
        didSet{
            contentLabel.text = statusViewModel?.statusModel?.retweeted_status?.text
            
            retweetViewBottomConstraint?.uninstall()
            //转发中带图
            if statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count > 0 {
                pictureView.pictureInfos = statusViewModel?.statusModel?.retweeted_status?.pic_urls
                self.snp_updateConstraints(closure: { (make) -> Void in
                    retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
                  pictureView.hidden = false
                })
            }else{  //转发中无图
                self.snp_updateConstraints(closure: { (make) -> Void in
                    retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                    pictureView.hidden = true
                })
            }
        }
        
    }

    override init(frame: CGRect) {
        super.init(frame:frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
//        backgroundColor = UIColor.lightGrayColor()
        backgroundColor = RGB(237, green: 237, blue: 237)
        // 添加控件
        addSubview(contentLabel)
        addSubview(pictureView)
        
        // 约束
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.top.equalTo(10)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
            make.size.equalTo(CGSize(width: 100, height: 100))
            make.leading.equalTo((SCREENW - 250)/2)
        }
        
        
        self.snp_makeConstraints { (make) -> Void in
            retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }
        
        
    }
    
    // 转发微博
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textSize: 15, maxWidth: SCREENW - 20)
    
    //转发带图片
    private lazy var pictureView: ZYStatusPictureView = ZYStatusPictureView()

}
